﻿using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using Teigha.Core;

namespace Teigha.TD
{
	public class OdDbIndexUpdateData : IDisposable
	{
		[EditorBrowsable(EditorBrowsableState.Never)]
		public OdDbIndexUpdateData(IntPtr cPtr, bool cMemoryOwn)
		{
			this.swigCMemOwn = cMemoryOwn;
			this.swigCPtr = new HandleRef(this, cPtr);
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public static HandleRef getCPtr(OdDbIndexUpdateData obj)
		{
			if (obj != null)
			{
				return obj.swigCPtr;
			}
			return new HandleRef(null, IntPtr.Zero);
		}

		~OdDbIndexUpdateData()
		{
			this.Dispose();
		}

		public virtual void Dispose()
		{
			if (this.swigCPtr.Handle != IntPtr.Zero)
			{
				if (this.swigCMemOwn)
				{
					lock (this.locker)
					{
						if (this.swigCPtr.Handle != IntPtr.Zero && this.swigCMemOwn)
						{
							this.swigCMemOwn = false;
							TD_DbPINVOKE.delete_OdDbIndexUpdateData(this.swigCPtr);
						}
					}
					this.swigCMemOwn = false;
				}
				this.swigCPtr = new HandleRef(null, IntPtr.Zero);
			}
			GC.SuppressFinalize(this);
		}

		public OdDbObjectId objectBeingIndexedId()
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr cPtr = TD_DbPINVOKE.OdDbIndexUpdateData_objectBeingIndexedId(this.swigCPtr);
			OdDbObjectId result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject(new OdDbObjectId(cPtr, true));
				result = new OdDbObjectId(cPtr, false);
			}
			else
			{
				result = new OdDbObjectId(cPtr, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public void addId(OdDbObjectId objectId)
		{
			TD_DbPINVOKE.OdDbIndexUpdateData_addId(this.swigCPtr, OdDbObjectId.getCPtr(objectId));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public bool setIdFlags(OdDbObjectId objectId, byte flags)
		{
			bool result = TD_DbPINVOKE.OdDbIndexUpdateData_setIdFlags(this.swigCPtr, OdDbObjectId.getCPtr(objectId), flags);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public bool setIdData(OdDbObjectId objectId, uint data)
		{
			bool result = TD_DbPINVOKE.OdDbIndexUpdateData_setIdData(this.swigCPtr, OdDbObjectId.getCPtr(objectId), data);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public bool getIdData(OdDbObjectId objectId, out uint data)
		{
			bool result = TD_DbPINVOKE.OdDbIndexUpdateData_getIdData(this.swigCPtr, OdDbObjectId.getCPtr(objectId), out data);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public bool getIdFlags(OdDbObjectId objectId, out byte flags)
		{
			bool result = TD_DbPINVOKE.OdDbIndexUpdateData_getIdFlags(this.swigCPtr, OdDbObjectId.getCPtr(objectId), out flags);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public bool getFlagsAndData(OdDbObjectId objectId, out byte flags, out uint data)
		{
			bool result = TD_DbPINVOKE.OdDbIndexUpdateData_getFlagsAndData(this.swigCPtr, OdDbObjectId.getCPtr(objectId), out flags, out data);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		private object locker = new object();

		private HandleRef swigCPtr;

		protected bool swigCMemOwn;

		public enum UpdateFlags
		{
			kModified = 1,
			kDeleted,
			kProcessed = 4,
			kUnknownKey = 8
		}
	}
}
